//
//  TZBaseViewController.m
//  一些零碎的知识
//
//  Created by user on 16/3/19.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "TZBaseViewController.h"


@interface TZBaseViewController()

@end

@implementation TZBaseViewController

#warning 数组越界注意点  1.忘了写懒加载 2.创建重用cell 一定按照组用section 行用row  3.数据源的方法

/*
 抽取基类 为了便于重用
 
 
 
 */
- (NSMutableArray *)groups{
    
    if (_groups == nil) {
        _groups = [NSMutableArray array];
    }
    return _groups;
}

- (void)viewDidLoad{
    [super viewDidLoad];

    self.tableView.backgroundColor = [UIColor whiteColor];

    
}


static NSString *ID = @"cell";
#pragma mark 数据源

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
   
    
    
    return self.groups.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    TZGroupModel *group = self.groups[section];

    return group.items.count;
    
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    TZTableViewCell *cell = [TZTableViewCell cellWithTableView:tableView];
    
    TZGroupModel *model = self.groups[indexPath.section];
    TZRowModel *row = model.items[indexPath.row];
    cell.model = row;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TZGroupModel *group = self.groups[indexPath.section];
    
    TZRowModel *row = group.items[indexPath.row];

    //取出当前row模型 如果row类是TZRowPush 强转成TZRowPush
    if ([row isKindOfClass:[TZRowPushModel class]]) {
        
        TZRowPushModel *model = (TZRowPushModel*)row;
        //创建跳转的 控制器
        UIViewController*vc = [[model.pushViewController alloc] init];
        
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    
    
}

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    TZGroupModel *group = self.groups[section];
    return group.headerTitle;
    
}
@end

